package com.cskaoyan._05servlet_cart;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author Macro_Ray
 * @since 2024/5/2 上午11:17
 */
@WebServlet("/item")
public class ItemServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        String id = req.getParameter("id");

//        if (StringUtil.isEmpty(id)) {
//            resp.getWriter().println("商品id不能为空");
//            return;
//        }
//        List<Product> productList = (List<Product>) getServletConfig().getAttribute("productList");
//
//        for (Product product : productList) {
//            if (product.getId().equals(id)) {
//                resp.getWriter().println(product);
//            }
//        }
        resp.getWriter().println("<div><a href='" + req.getContextPath() + "/index" + "'>返回首页</a></div>");
        resp.getWriter().println("<div><a href='" + req.getContextPath() + "/addCart?id" + id + "'>加入购物车</a></div>");
        resp.getWriter().println("<div><a href='" + req.getContextPath() + "/viewCart" + "'>查看购物车</a></div>");
    }
}

